﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MsgCenter.DAL.Base;
using Utility.Model;
using Hxj.Data;
using System.Data;

namespace MsgCenter.BLL.Impl
{
    public class BLL_SysReg
    {
        private readonly BaseService dal = new BaseService();
        /// <summary>
        /// 保存修改
        /// </summary>
        /// <param name="model">对应实体</param>
        /// <param name="strSelectUserID">分配的用户</param>
        public void Save(Sys_AppReg model, string strSelectUserID)
        {
            DbTrans trans = dal.GetDataBase().BeginTransaction();
            try
            {
                dal.Save<Sys_AppReg>(model, trans);
                //dal.ExecuteNonQuery("delete Sys_AppReg_User where AppID='" + model.AppID + "'", trans);
                //if (strSelectUserID.Length > 0)
                //{
                //    string[] idList = strSelectUserID.Trim(',').Split(',');
                //    foreach (string strUserID in idList)
                //    {
                //        dal.ExecuteNonQuery(" insert into Sys_AppReg_User(AppID,UserID)  values ('" + model.AppID + "','" + strUserID + "')", trans);
                //    }
                //}
                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                throw ex;
            }
            finally
            {
                trans.Close();
            }
        }
        /// <summary>
        /// 删除,修改状态
        /// </summary>
        /// <param name="strDataID">数据ID</param>
        public void DeleteApp(string strDataID)
        {
            if (strDataID.Length > 0)
            {
                string[] idList = strDataID.Trim(',').Split(',');
                DbTrans trans = dal.GetDataBase().BeginTransaction();
                try
                {
                    foreach (string strAppID in idList)
                    {
                        dal.ExecuteNonQuery("Update Sys_AppReg set Isdelete=1 where AppID='" + strAppID + "'", trans);
                    }
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
                finally
                {
                    trans.Close();
                }
            }
        }
        /// <summary>
        /// 获取对象实体
        /// </summary>
        /// <param name="strDataID">数据ID</param>
        /// <returns>Sys_ApplicationReg</returns>
        public Sys_AppReg GetAppModel(string strDataID)
        {
            return dal.GetModel<Sys_AppReg>(Sys_AppReg._.AppID == strDataID);
        }
        /// <summary>
        /// 获取对象Table
        /// </summary>
        /// <param name="wcp"></param>
        /// <returns></returns>
        public DataTable GetRegAppTable(WhereClip wcp)
        {
            return dal.GetTable<Sys_AppReg>(wcp);
        }
    }
}
